import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import CommentPost from 'flarum/forum/components/CommentPost';
import Post from 'flarum/common/models/Post';
import Model from 'flarum/common/Model';
import ItemList from 'flarum/common/utils/ItemList';

app.initializers.add('echo/hello', () => {
  Post.prototype.ip_city = Model.attribute('ip_city');
  extend(CommentPost.prototype, 'headerItems', function (this: CommentPost, items: ItemList) {
    const post = this.attrs.post;
    const ipcity = post.ip_city() || '';
    items.add('city', m('.PostMeta', ipcity ? "IP来自" + ipcity : ''));
  })
});
